package qmsz.api.service.impl;

import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qmsz.api.dao.QMDeliverInfoDAO;
import qmsz.api.domain.QMChargeOrderDeliverInfo;
import qmsz.api.domain.QMUserDeliverInfo;
import qmsz.api.service.QMDeliverInfoService;

@Service
public class QMDeliverInfoServiceImpl implements QMDeliverInfoService {
	
	private static final Logger logger = Logger.getLogger(QMDeliverInfoServiceImpl.class);

	@Autowired
	private QMDeliverInfoDAO qmdeliverinfoDAO;

	@Override
	public List<QMUserDeliverInfo> listUserDeliverInfoByUserID(String userID) {
		List<QMUserDeliverInfo> value = null;
		try {
			value = qmdeliverinfoDAO.listUserDeliverInfoByUserID(userID);
		} catch (Exception e) {
			logger.error("query error", e);
			value = null;
		}
		return value;
	}
	
	@Override
	public boolean insertChargeOrderDeliverInfo(QMChargeOrderDeliverInfo codi) {
		codi.setId(RandomStringUtils.randomAlphanumeric(32));
		boolean flag = false;
		try {
			flag = qmdeliverinfoDAO.insertChargeOrderDeliverInfo(codi) > 0;
		} catch (Exception e) {
			logger.error("insert error", e);
			flag = false;
		}
		return flag;
	}

	@Override
	public List<QMChargeOrderDeliverInfo> listChargeOrderDeliverInfoByUserID(String userID) {
		List<QMChargeOrderDeliverInfo> value = null;
		try {
			value = qmdeliverinfoDAO.listChargeOrderDeliverInfoByUserID(userID);
		} catch (Exception e) {
			logger.error("query error", e);
			value = null;
		}
		return value;
	}
	
	@Override
	public boolean updateUserDeliverInfo(QMUserDeliverInfo udi) {
		boolean flag = false;
		try {
			flag = qmdeliverinfoDAO.updateUserDeliverInfo(udi) > 0;
		} catch (Exception e) {
			logger.error("update error", e);
			flag = false;
		}
		return flag;
	}

	@Override
	public boolean insertUserDeliverInfo(QMUserDeliverInfo udi) {
		udi.setId(RandomStringUtils.randomAlphanumeric(32));
		boolean flag = false;
		try {
			flag = qmdeliverinfoDAO.insertUserDeliverInfo(udi) > 0;
		} catch (Exception e) {
			logger.error("insert error", e);
			flag = false;
		}
		return flag;
	}
}
